package com.eastcom.providor.util;

import java.util.Date;

import com.eastcom.canicula.stope.utils.DateUtil;

public class TimeKit {

	public static long getReferTime(long referTime, long timesliceLength)
	{
		if(timesliceLength == 0)
			return referTime;
		
		long startTime = -8 * 3600 * 1000;
		long lRefer = referTime - (referTime - startTime) % (timesliceLength);
		
		return lRefer;
	}
	
	public static long getCurrentReferTime(long startTime, long timesliceLength)
	{		
		Date today = new Date();
		long lCurtime = today.getTime();
		
		if(timesliceLength == 0)
			return lCurtime;
		
		if (startTime == 0)
			startTime = -8 * 3600 * 1000;
		
		long lRefer = lCurtime - (lCurtime - startTime) % (timesliceLength);
		
		return lRefer;
	}
	
	public static void main(String[] args)
	{
		System.out.println(DateUtil.LongToDate(TimeKit.getCurrentReferTime(0, 3600000)));
	}
	
	public static long getExecTimes(long lStarttime,long lEndtime,long iOffset)
	{
		long times=0;
		if (iOffset == 0)		//û�й涨ʱ������ֱ��ִ��һ��
			times = 1;
		else if (((lEndtime - lStarttime) / iOffset) == 0)
			times = 0;
		else if (((lEndtime - lStarttime) % iOffset) != 0)
			times = ((lEndtime - lStarttime) / iOffset) + 1;
		else
			times = (lEndtime - lStarttime) / iOffset;
		return times;
	}
}
